package com.jdwx.opengl.mvp.model.impl;


import android.os.Handler;
import android.text.TextUtils;

import com.jdwx.opengl.mvp.model.StudentLoginModel;
import com.jdwx.opengl.mvp.model.entity.Student;
import com.jdwx.opengl.mvp.presenter.OnLoginFinishedListener;

/**
 * 接口实现类
 */
public class StudentLoginModelImpl implements StudentLoginModel {
    @Override
    public void login(Student student, final OnLoginFinishedListener listener) {
        final String username = student.name;
        final String password = student.pass;
        //这里模拟网络请求
        new Handler().postDelayed(new Runnable() {
            @Override public void run() {
                boolean error = false;
                if (TextUtils.isEmpty(username)){
                    listener.onUsernameError();//model层里面回调listener
                    error = true;
                }
                if (TextUtils.isEmpty(password)){
                    listener.onPasswordError();
                    error = true;
                }
                if (!error){
                    listener.onSuccess();
                }
            }
        }, 2000);
    }
}